package com.guochuang.yunwang.promanager.serviceImpl;

import com.guochuang.yunwang.promanager.dao.ProjectAnalysisMapper;
import com.guochuang.yunwang.promanager.service.ProjectAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class ProjectAnalysisServiceImpl implements ProjectAnalysisService {

    @Autowired
    private ProjectAnalysisMapper projectAnalysisMapper;

    @Autowired
    private SimpleDateFormat simpleDateFormat;

    @Override
    public List<Map<String, Object>> getProjectCategoryInfoByCategory() {
        return projectAnalysisMapper.getProjectCategoryInfoByCategory();
    }

    @Override
    public List sortbycategory() {
        return projectAnalysisMapper.sortbycategory();
    }

    @Override
    public List sortbypriority() {
        return projectAnalysisMapper.sortbypriority();
    }

    @Override
    public Map<String, Object> getProjectAmountByMonth() {

        String year = simpleDateFormat.format(System.currentTimeMillis()).split("-")[0];

        List<Map<String, Object>> res = projectAnalysisMapper.getProjectAmountByMonth(year);

        List<BigDecimal> values = new ArrayList<>();

        List<Integer> month = new ArrayList<>();

        for (Map<String, Object> re : res) {
            values.add((BigDecimal) re.get("value"));
            month.add((Integer) re.get("month"));
        }
        Map<String,Object> ress = new HashMap<>();

        ress.put("key",month);

        ress.put("value",values);

        return ress;
    }

    @Override
    public Map<String, Object> getProjectNums() {

        // 获取已经完结的项目数据
        Integer complete = projectAnalysisMapper.getProjectCompleteNums("complete");

        Integer nocomplete = projectAnalysisMapper.getProjectCompleteNums("nocomplete");

        // 获取项目总金额
        Double money = projectAnalysisMapper.getProjectAllMoney();

        Map<String,Object> rec = new HashMap<>();

        rec.put("complete",complete);

        rec.put("nocomplete",nocomplete);

        rec.put("money",money);

        return rec;
    }

    @Override
    public List<Map<String, Object>> getProjectInfoByArea() {
        return projectAnalysisMapper.getProjectAreaInfo();
    }
}
